﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Com.AAS.Toolbox.DataMirror.Config;
using Com.AAS.Toolbox.DataMirror.Server;
using Com.AAS.Toolbox.DataMirror.Setting;

namespace Com.AAS.Toolbox.DataMirror.GUI
{
    class FileSystemCoreSettingGUI
    {
        public Form InitSettingGUI(FileSystemConfig cfg, FileSystemCoreServer server)
        {
            // 主界面图标
            Icon icon = new Icon(@".\\logo.ico");

            // 设置窗口实例化
            SettingForm settingForm = new SettingForm();


            // 设置窗口实例化
            LogForm logForm = new LogForm();


            MenuItem itemSycn = new MenuItem("(&Y)Sync", new EventHandler((object sender, EventArgs e) =>
            {
                server.Sync();
            }));

            MenuItem itemLog = new MenuItem("(&L)Log", new EventHandler((object sender, EventArgs e) =>
            {
                if (!logForm.Visible)
                    logForm.Visible = true;
                else
                    logForm.Visible = !true;
            }));

            // 主窗口实例化
            NotifyIconForm notifyForm = new NotifyIconForm("Brid", icon, new MenuItem[] { itemSycn, itemLog });


            // 设置窗口触发关闭事件
            settingForm.FormClosing += new FormClosingEventHandler(
                (object sender, FormClosingEventArgs e) =>
                {
                    e.Cancel = true;
                    (sender as Form).Hide();

                });

            // 主窗口双机任务栏图标
            notifyForm.NotifyDoubleClick += new EventHandler((object sender, EventArgs e) =>
            {
                if (!settingForm.Visible)
                    settingForm.ShowDialog();
                else
                    settingForm.Hide();
            });

            // 主窗口退出
            notifyForm.FormClosed += new FormClosedEventHandler((object sender, FormClosedEventArgs e) =>
            {
                settingForm.Close();
            });


            return notifyForm;
        }
    }
}
